home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
Information
/
CSMP Digest
/
volume 1
/
csmp-v1-202.txt
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
UTF-8
Wrap
Text File
|
1994-12-08
|
41.8 KB
|
1,282 lines
|
[
TEXT/R*ch
]
C.S.M.P. Digest Sun, 01 Nov 92 Volume 1 : Issue 202
Today's Topics:
Help: mounting appleshare volumes
#pragma parameter in MPW C++
Berkeley Socket Emulation for MacTCP (possible FAQ)?
fast serial I/O in Think C with extra hardware?
Easter was: Re: Algorithm for Day-Of-Week NEEDED
Help: Sample code wanted
Random() needs some Thorazine (Help!)
The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
The digest is a collection of article threads from the internet newsgroup
comp.sys.mac.programmer. It is designed for people who read c.s.m.p. semi-
regularly and want an archive of the discussions. If you don't know what a
newsgroup is, you probably don't have access to it. Ask your systems
administrator(s) for details. (This means you can't post questions to the
digest.)
Each issue of the digest contains one or more sets of articles (called
threads), with each set corresponding to a 'discussion' of a particular
subject. The articles are not edited; all articles included in this digest
are in their original posted form (as received by our news server at
cs.uoregon.edu). Article threads are not added to the digest until the last
article added to the thread is at least one month old (this is to ensure that
the thread is dead before adding it to the digest). Article threads that
consist of only one message are generally not included in the digest.
The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
[128.223.8.8] in the directory /pub/mac/csmp-digest. Be sure to read the
file /pub/mac/csmp-digest/README before downloading any files. The most
recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
directory /info-mac/digest/csmp. If you don't have ftp capability, the sumex
archive has a mail server; send a message with the text '$MACarch help' (no
quotes) to LISTSERV@ricevm1.rice.edu for more information.
The digest is also available via email. Just send a note saying that you
want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
automatically receive each new issue as it is created. Sorry, back issues
are not available through the mailing list.
Send administrative mail to mkelly@cs.uoregon.edu.
-------------------------------------------------------
From: perrins@vax.oxford.ac.uk
Subject: Help: mounting appleshare volumes
Date: 23 Sep 92 15:28:26 GMT
Organization: Oxford University VAX 6620
Help wanted with AppleShare ....
Does anyone out there know how to mount an AppleShare volume from within an
application (written in pascal or C). There is a hypercard XCMD which does what
I want (gets the username,password,zonename,servername etc all lined up and
then mounts the volume if it exists).
I need this 'cos I have an application which runs at startup to force a login
to a server, and set the chooser name to the appleshare username, as a way of
validating users on a large network. This relies on the fact that appleshare
offers a login automatically at boot up time if so desired, on our system this
is followed by the startup application. However if the user
logs out by throwing away the server icon another user logging in in the
standard way does not have his chooser name fixed.
Any ideas most welcome...
R.McCleery - dept of zoology oxford uk.
+++++++++++++++++++++++++++
From: larimer@zeus.cdc.com (Mark D. Larimer)
Date: 27 Sep 92 05:42:34 GMT
Organization: Control Data Systems, Inc.
In article <1992Sep23.162826.9004@vax.oxford.ac.uk> ,
perrins@vax.oxford.ac.uk writes:
>Does anyone out there know how to mount an AppleShare volume from within
an
>application (written in pascal or C). There is a hypercard XCMD which
does what
>I want (gets the username,password,zonename,servername etc all lined up
and
>then mounts the volume if it exists).
>I need this 'cos I have an application which runs at startup to force a
login
>to a server, and set the chooser name to the appleshare username, as a
way of
>validating users on a large network. This relies on the fact that
appleshare
>offers a login automatically at boot up time if so desired, on our
system this
>is followed by the startup application. However if the user
>logs out by throwing away the server icon another user logging in in the
>standard way does not have his chooser name fixed.
>Any ideas most welcome...
I've got pascal code that does this. System 6 users are required to have
version 3.0
of the AppleShare rdev (Chooser device) in their System Folder for this
to work, but
according to Apple itself, without AppleShare 3.0, there is no other way
to do it
under System 6 other than the XCMD you mentioned above. System 7 users
will have no
problem. Note that the server being mounted doesn't have to be running
AppleShare 3.0;
only the Mac mounting the server needs to have the AppleShare 3.0
resource.
Good luck and let me know how it goes...
Mark D. Larimer
(Control Data Systems, Inc.) && (University of Minnesota)
Mark.D.Larimer@zeus.cdc.com
{-------------------------------------------------------------------}
Function Pack (s1,s2,s3,s4,s5,s6 : Str255) : packedType; FORWARD;
{-------------------------------------------------------------------}
{ The guts of the proc that mounts a server in either }
{ System 7 or System 6 with AppleShare 3.0 rdev. }
Procedure MountIt;
var err : OSErr;
errStr : Str255;
myBuffer : AFPVolMountInfo;
myParamBlock: ParamBlockRec;
begin
with myBuffer do begin
media:='afpm'; { type of volume; four-character code; afpm =
AppleShareMediaType }
flags:=0; { reserved; must be set to 0 }
nbpInterval:=8; { Name-Binding Protocol (NBP) retry interval }
nbpCount:=3; { NBP retry count }
uamType:=2; { user authentication method; 2 = kPassword =
8-byte password }
zoneNameOffset:=24; { offset from start of record to zone name }
serverNameOffset:=57; { to server name }
volNameOffset:=89; { to volume name
}
userNameOffset:=117; { to user name }
userPassWordOffset:=149;{ to user
password }
volPassWordOffset:=158; { to volume
password }
{ user
volume }
{ zone name server volume username pw
pw }
afpData:=Pack('ZONE NAME','Cool Server','Volume
I','username','password','password');
length:=sizeof(myBuffer); { length of mounting information }
end;
myParamBlock.ioCompletion:=nil; { proc pointer to execute upon
completion }
myParamBlock.ioBuffer:=@myBuffer; { pointer to mounting information
record }
err:=PBVolumeMount(@myParamBlock); { mount the volume }
if err<>0 then begin
NumToString(err,errStr);
ParamText('Error during PBVolumeMount',errStr,'','');
itemHit:=Alert(idAlert,nil);
end
else
serverVRefNum:=myParamBlock.ioVRefNum; { if successful, vol ref num
returned }
end;
{----------------------------------------------------------------------
- ------}
{ Lay the mounting information into the buffer at the proper offset
locations }
Function Pack(s1,s2,s3,s4,s5,s6:Str255):packedType;
var i,j : integer;
Data : packedType;
begin
j:=2;
Data[1]:=chr(length(s1));
for i:=1 to length(s1) do begin
Data[j]:=s1[i];
j:=j+1;
end;
j:=35;
Data[34]:=chr(length(s2));
for i:=1 to length(s2) do begin
Data[j]:=s2[i];
j:=j+1;
end;
j:=67;
Data[66]:=chr(length(s3));
for i:=1 to length(s3) do begin
Data[j]:=s3[i];
j:=j+1;
end;
j:=95;
Data[94]:=chr(length(s4));
for i:=1 to length(s4) do begin
Data[j]:=s4[i];
j:=j+1;
end;
j:=127;
Data[126]:=chr(length(s5));
for i:=1 to length(s5) do begin
Data[j]:=s5[i];
j:=j+1;
end;
j:=136;
Data[135]:=chr(length(s6));
for i:=1 to length(s6) do begin
Data[j]:=s6[i];
j:=j+1;
end;
Pack:=Data;
end;
{--------------------------------------------------------------}
+++++++++++++++++++++++++++
From: larimer@zeus.cdc.com (Mark D. Larimer)
Date: 27 Sep 92 06:24:08 GMT
Organization: Control Data Systems, Inc.
Let me rephrase that...
{-------------------------------------------------------------------}
Function Pack (s1,s2,s3,s4,s5,s6 : Str255) : packedType; FORWARD;
{-------------------------------------------------------------------}
{ The guts of the proc that mounts a server in either }
{ System 7 or System 6 with AppleShare 3.0 rdev. }
Procedure MountIt;
var err : OSErr;
errStr : Str255;
myBuffer : AFPVolMountInfo;
myParamBlock: ParamBlockRec;
begin
with myBuffer do begin
media:='afpm'; { type of volume; four-character code; afpm =
AppleShareMediaType }
flags:=0; { reserved; must be set to 0 }
nbpInterval:=8; { Name-Binding Protocol (NBP) retry interval }
nbpCount:=3; { NBP retry count }
uamType:=2; { user authentication method; 2 = kPassword = 8-byte
password }
zoneNameOffset:=24; { offset from start of record to zone name }
serverNameOffset:=57; { offset to server name }
volNameOffset:=89; { offset to volume name }
userNameOffset:=117; { offset to user name }
userPassWordOffset:=149; { offset to user password }
volPassWordOffset:=158; { offset to volume password }
{
user volume }
{ zone name server volume username pw
pw }
afpData:=Pack('ZONE NAME','Cool Server','Volume
I','username','password','password');
length:=sizeof(myBuffer); { length of mounting information }
end;
myParamBlock.ioCompletion:=nil; { proc pointer to execute upon
completion }
myParamBlock.ioBuffer:=@myBuffer; { pointer to mounting information
record }
err:=PBVolumeMount(@myParamBlock); { mount the volume }
if err<>0 then begin
NumToString(err,errStr);
ParamText('Error during PBVolumeMount',errStr,'','');
itemHit:=Alert(idAlert,nil);
end
else
serverVRefNum:=myParamBlock.ioVRefNum; { if successful, vol ref
num returned }
end;
{----------------------------------------------------------------------
- ------}
{ Lay the mounting information into the buffer at the proper offset
locations }
Function Pack(s1,s2,s3,s4,s5,s6:Str255):packedType;
var i,j : integer;
Data : packedType;
begin
j:=2;
Data[1]:=chr(length(s1));
for i:=1 to length(s1) do begin
Data[j]:=s1[i];
j:=j+1;
end;
j:=35;
Data[34]:=chr(length(s2));
for i:=1 to length(s2) do begin
Data[j]:=s2[i];
j:=j+1;
end;
j:=67;
Data[66]:=chr(length(s3));
for i:=1 to length(s3) do begin
Data[j]:=s3[i];
j:=j+1;
end;
j:=95;
Data[94]:=chr(length(s4));
for i:=1 to length(s4) do begin
Data[j]:=s4[i];
j:=j+1;
end;
j:=127;
Data[126]:=chr(length(s5));
for i:=1 to length(s5) do begin
Data[j]:=s5[i];
j:=j+1;
end;
j:=136;
Data[135]:=chr(length(s6));
for i:=1 to length(s6) do begin
Data[j]:=s6[i];
j:=j+1;
end;
Pack:=Data;
end;
{--------------------------------------------------------------}
---------------------------
From: liran@bimacs.BITNET (Eshel Liran)
Subject: #pragma parameter in MPW C++
Date: 24 Sep 92 08:46:12 GMT
Organization: Math & CS, BarIlan U, Ramat-Gan, Israel
In the AppleShare 3.0 Developers Kit there is a direct assembler function which
comes under the following compiler directive:
#pragma parameter __D0 SynchServerDispatch(__A0)
It worked fine in THINK C but when I tried to use it in MPW C++ it didn't work.
After viewing the assembly code created by the compiler it seems that it
didn't work because of the #pragma compiler directive.
Any solutions ?
- ----------------------------------------
Liran Eshel,
Bar-Ilan University, ISRAEL
liran@bimacs.cs.biu.ac.il
- ----------------------------------------
+++++++++++++++++++++++++++
From: ksand@apple.com (Kent Sandvik)
Date: 26 Sep 92 01:17:09 GMT
Organization: Apple
In article <4224@bimacs.BITNET>, liran@bimacs.BITNET (Eshel Liran) wrote:
> In the AppleShare 3.0 Developers Kit there is a direct assembler function which
> comes under the following compiler directive:
>
> #pragma parameter __D0 SynchServerDispatch(__A0)
>
> It worked fine in THINK C but when I tried to use it in MPW C++ it didn't work.
> After viewing the assembly code created by the compiler it seems that it
> didn't work because of the #pragma compiler directive.
I don't have the kit handy, but I think that the C++ wrappers are
missing, so the function name is maybe mangled, and the linker does not
find the right function. Place something like this around the assembler
functions (example stolen from MPW Start.h):
#ifdef __cplusplus
extern "C" {
#endif
#pragma parameter GetDefaultStartup(__A0)
pascal void GetDefaultStartup(DefStartPtr paramBlock)
= 0xA07D;
#pragma parameter SetDefaultStartup(__A0)
pascal void SetDefaultStartup(DefStartPtr paramBlock)
= 0xA07E;
...
pascal void SetTimeout(short count);
pascal void GetTimeout(short *count);
#ifdef __cplusplus
}
#endif
Cheers,
Kent/DTS
- -------------------
Kent Sandvik (UUCP: ....!apple!ksand; INTERNET: ksand@apple.com)
DISCLAIMER: Private activities on the Net.
---------------------------
From: dank@blacks.jpl.nasa.gov (Daniel R. Kegel)
Subject: Berkeley Socket Emulation for MacTCP (possible FAQ)?
Organization: Image Analysis Systems Group, JPL
Date: Thu, 24 Sep 1992 15:53:26 GMT
Hi,
I'm looking for a C library that makes MacTCP look like Berkeley Sockets.
I hear that MIT wrote something like this, and have heard rumors of
other packages. Has anybody heard of such a thing?
- - Dan Kegel (dank@blacks.jpl.nasa.gov)
+++++++++++++++++++++++++++
From: ejohnson@void.ncsa.uiuc.edu (Eric E. Johnson)
Date: 24 Sep 92 17:01:11 GMT
Organization: University of Illinois at Urbana
dank@blacks.jpl.nasa.gov (Daniel R. Kegel) writes:
>I'm looking for a C library that makes MacTCP look like Berkeley Sockets.
>I hear that MIT wrote something like this, and have heard rumors of
>other packages. Has anybody heard of such a thing?
There are two libraries that I know of.
The first one is a sockets implementation that's available somewhere
on NCSA's ftp machine, ftp.ncsa.uiuc.edu. Its not officially part of
NCSA's software, so it is unsupported.
The second package is one that Igor Livshits, John Newlin and I worked
on; it is *not* sockets. But, it does demonstrate how to use
MacTCP. Its a class library for Think C 5.0, and demonstrates how to
use a majority of the functions. You can find that at ftp.brown.edu,
in pub/tcl/contributors/University_of_Illinois.
Eric
+++++++++++++++++++++++++++
From: ldh@svl.cdc.com (Lawrence D. Hare)
Date: 28 Sep 92 16:38:49 GMT
Organization: Control Data Systems
In article <ejohnson.717354071@void> Eric E. Johnson,
ejohnson@void.ncsa.uiuc.edu writes:
>>I'm looking for a C library that makes MacTCP look like Berkeley
Sockets.
>>I hear that MIT wrote something like this, and have heard rumors of
>>other packages. Has anybody heard of such a thing?
BSD sockets for MPW (and maybe in Think C?) : ftp to
madhaus.utcs.toronto.ca
Socket library for MacTCP based on BSD: ftp to net-dist.mit.edu and get
the
file jon/bsd-mac-compat.sit.hqx. Problems to jon rochlis (jon@mit.edu)
This information originally supplied by sylviae@uga.cc.uga.edu.
Hope this helps
- --
Lawrence D. Hare
---------------------------
From: hase@netmbx.netmbx.de (Hartmut Semken)
Subject: fast serial I/O in Think C with extra hardware?
Organization: netmbx, Berlin, Germany
Date: Thu, 24 Sep 1992 16:20:19 GMT
Hello out there.
Sure it is possible to run the Macs modem port at up to 57600 Baud.
But what if You want (need) to be faster than that? (LocalTalk runs
faster, doen't it?)
Has anyone tried to feed the ACIA with an external clock? How do I set
up the port to accept an external clock.
And how do I run the port in synchronous mode? I am told this beiing
impossible on IIfx and Q900/Q950. If that is right, I'll probably need
an external clock.
Has anyone already built an parallel to serial converter running fast?
thanks
hase
- --
hase
Hartmut Semken, Lupsteiner Weg 67, 1000 Berlin 37 hase@netmbx.netmbx.de
" I liked ZORK. I loved THE PAWN, but then I needed
an adult adventure. I bought UNIX.
+++++++++++++++++++++++++++
From: thepope@bigboy (Michael Kohne)
Date: 25 Sep 92 23:14:11 GMT
Organization: Temple University
hase@netmbx.netmbx.de (Hartmut Semken) writes:
: Hello out there.
:
: Sure it is possible to run the Macs modem port at up to 57600 Baud.
: But what if You want (need) to be faster than that? (LocalTalk runs
: faster, doen't it?)
:
: Has anyone tried to feed the ACIA with an external clock? How do I set
: up the port to accept an external clock.
:
: And how do I run the port in synchronous mode? I am told this beiing
: impossible on IIfx and Q900/Q950. If that is right, I'll probably need
: an external clock.
: Has anyone already built an parallel to serial converter running fast?
:
: thanks
:
: hase
: Hartmut Semken, Lupsteiner Weg 67, 1000 Berlin 37 hase@netmbx.netmbx.de
Well, the Serial Chip on the Mac is the Zilog Z8530 SCC Serial Communications
Controller. Find someone with Zilog Databooks, and photocopy the relevant
pages. This will (after some deciphering) tell you how to do what you want.
As for the IIfx: This sort of thing will be harder, if at all possible on the
IIfx(and on some of the newer machines) because there is an IO Processor
inbetween the 680x0 and the SCC.
Have fun.
Michael Kohne
"Pope" Q.E.D
House of the Techno-Discordians, Aquatic Amusements Division.
P.S. could the original poster send me e-mail if you see this? There
has been some trouble posting from this machine in the past...
thepope@bigboy.cis.temple.edu
+++++++++++++++++++++++++++
From: bwilliam@iat.holonet.net (Bill Williams)
Organization: HoloNet (BBS: 510-704-1058)
Date: Tue, 29 Sep 1992 06:06:26 GMT
I (mostly a friend though) have hacked the serial driver to halve the
sample clock rate in the driver so that serial speeds double that of 57600
baud are available. In fact a loop cable linking bothe ports at 115,000
baud in and out at the same time on a standard IIci showed not problems
sending Zmodem protocol files.
On sad side effect:
Interrupts occured so frequently using both ports at this speed that
TickCount barely ever advanced!!!!!!!!!!!!!!!!!!!!
The chip could, not too safely, be halved again to go double the 115,000
baud but everyone I know only needs to go only 115,000 baud to support our
Telebit Worldblazer modems.
You'll figure it out.
(Check dartmouth LocalTalk/serial source from old Doctor dobbs, check MIDI
serial port stuff from various mactutors, get the zilog docs, get a
debugger/dissassembler.
115,000 baud is potentially quite simple.
Bill Williams
---------------------------
From: dm@stekt2.oulu.fi (Hannu Helminen)
Subject: Easter was: Re: Algorithm for Day-Of-Week NEEDED
Date: 24 Sep 92 20:06:00 GMT
Organization: University of Oulu, Dept. of EE, Finland
Does anyone have working C-code to determine when it is Easter in a
given year? It would be handy since I am currently writing a calendar
utility in C. Pointers to such code would also be appreciated.
Thanks in advance.
- --
_| _ _ Hannu dm@stekt.oulu.fi // Does anybody else in here
(_|| | ) Helminen dm@phoenix.oulu.fi \X/ feel the way I do?
+++++++++++++++++++++++++++
From: ebergman@nyx.cs.du.edu (Eric Bergman-Terrell)
Date: 25 Sep 92 13:55:56 GMT
Organization: Nyx, Public Access Unix at U. of Denver Math/CS dept.
In article <DM.92Sep24220600@stekt2.oulu.fi> dm@stekt2.oulu.fi (Hannu Helminen) writes:
>
>Does anyone have working C-code to determine when it is Easter in a
>given year? It would be handy since I am currently writing a calendar
>utility in C. Pointers to such code would also be appreciated.
>
>Thanks in advance.
>--
>
> _| _ _ Hannu dm@stekt.oulu.fi // Does anybody else in here
> (_|| | ) Helminen dm@phoenix.oulu.fi \X/ feel the way I do?
See "Date Management", Eric Bergman-Terrell in Computer Language, Dec. 90 or
Practical Astronomy with your Calculator, Peter Duffett-Smith, Oxford U. Press
or
Astronomical Formulae for Calculators, Jean Meeus, Willman-Bell, Inc.
Terrell
+++++++++++++++++++++++++++
From: karl@ima.isc.com (Karl Heuer)
Date: 25 Sep 92 21:41:43 GMT
Organization: Interactive Systems, Cambridge, MA 02138-5302
In article <DM.92Sep24220600@stekt2.oulu.fi> dm@stekt2.oulu.fi (Hannu Helminen) writes:
>Does anyone have working C-code to determine when it is Easter in a
>given year?
/*
* Table of Easter, 1970-2000; day in March (April if >31).
*/
int eastertab[] = {
29, 42, 33, 53, 45, 30, 49, 41, 26, 46, 37, 50, 42, 34, 53, 38, 30, 50,
34, 26, 46, 31, 50, 42, 34, 47, 38, 30, 43, 35, 54,
};
+++++++++++++++++++++++++++
From: db21@cbnewsc.cb.att.com (david.beyerl)
Organization: AT&T
Date: Sat, 26 Sep 1992 11:23:47 GMT
In article <DM.92Sep24220600@stekt2.oulu.fi>, dm@stekt2.oulu.fi (Hannu Helminen) writes:
>
> Does anyone have working C-code to determine when it is Easter in a
> given year? It would be handy since I am currently writing a calendar
> utility in C. Pointers to such code would also be appreciated.
>
An algorithm for the date of Easter is presented on pages
155-156 in "The Art of Computer Programming, Fundamental Algorithms,
Volume 1, by Knuth. Below is C-source I obtained from someone on the
net.
Dave Beyerl
att!ihlpm!db21
- ---------------------------------------------------------------------
>From att!world.std.com!geoff Thu Jan 09 12:31:28 0500 1992
Subject: Re: Easter Sunday algorythm
Here you go; enjoy.
# To unbundle, sh this file
echo easter.c 1>&2
sed 's/^X//' >easter.c <<'!'
X/*
X * easter - compute date of easter
X * see The Art of Computer Programming, Vol. 1, pp. 155-6.
X */
X# include <stdio.h>
X# include <time.h>
X# include <sys/types.h>
X# define CENTURY 100
X# define LEAP 4
X# define WEEK 7
X# define MARCH_DAYS 31
X# define APRIL 3
X# define METONIC 19
X# define BASEYEAR 1900 /* add to localtime(t)->tm_year */
X# define GREGORY 1582 /* start of gregorian calendar */
main(argc, argv)
char ** argv;
X{
X if (argc > 2)
X fprintf(stderr, "usage: easter [year]\n");
X else if (argc == 2)
X easter(atoi(argv[1]));
X else
X easter(this_year());
X exit(0);
X}
this_year()
X{
X register struct tm * lp;
X time_t t;
X extern struct tm * localtime();
X extern time_t time();
X t = time(&t);
X lp = localtime(&t);
X if (lp->tm_mon > APRIL)
X lp->tm_year++;
X return(lp->tm_year + BASEYEAR);
X}
easter(year)
register int year;
X{
X register int epact, fullmoon;
X int golden, century, noleap;
X if (year < GREGORY) {
X printf("%d: before Gregory\n", year);
X return;
X }
X golden = year % METONIC + 1;
X century = year / CENTURY + 1;
X noleap = 3 * century / LEAP - 12;
X epact = (11 * golden + 20 +
X (8 * century + 5) / 25 - 5 /* moon orbit correction */
X - noleap) % 30;
X if (epact < 0)
X epact += 30; /* make remainder positive */
X if (epact == 25 && golden > 11 || epact == 24)
X ++epact;
X fullmoon = 44 - epact;
X if (fullmoon < 21)
X fullmoon += 30;
X fullmoon += WEEK - (
X (int)(5L * year / LEAP) - noleap - 10
X + fullmoon) % WEEK; /* advance to Sunday */
X if (fullmoon > MARCH_DAYS)
X printf("%d April", fullmoon - MARCH_DAYS);
X else
X printf("%d March", fullmoon);
X printf(" %d\n", year);
X}
!
---------------------------
From: tbl@rock.concert.net (Ted Lowery)
Subject: Help: Sample code wanted
Date: 24 Sep 92 17:14:11 GMT
Organization: MacSolutions
Hi All-
I posted a sample code request about a week ago, and really did not get any
decent responses. So I am going to try again.
I have been struggling with some code that you might be able to help me with.
What I am trying to do is patch to the shutdown command and perform some
special clean-up everytime at shutdown. I have an application which will do
exactly what I want, and I have been successfully able to make it into an init
that will do it while the init is loading.
But what I can't figure out how to do is get it to load and stay around until
shutdown is invoked. I have installed entrypoint as a shutdown procptr, but
it crashes every time. I suspect my code is disappearing right after the init
finishes loading. I got the doohicky sample code off the developer disk, but
so far haven't been able to make heads or tails of it.
I see tons of shareware and freeware stuff that does this kind of thing all
the time. I am sure some of you are doing it with think C 5.0. Would someone
PLEASE send me some source code which will explain the proper methods to me.
Not only code, but directions on how to set up the project properly and any
other useful information you might have. I know that some of you must have
been frustrated trying to do this yourself.
I cannot really offer anything in return for the sources, except the
possibility that I might write something really cool and useful someday!
I understand how precious some of you feel your code is, but isn't this sort
of thing one of the main reasons the net is here?
Please don't write me back and say something like "look on sumex or
ftp.apple.com. there's lots of good stuff there!". I have already looked,
but nothing seems to jump out at me as to be the solution. And at 2400bps,
I really don't want to download the entire archives hunting for that
preverbial needle in the haystack.
Also, please don't write me back saying to check out doohickey or TN256.
I have again looked at these, and so far the lightbulb is still off.
What I really want is an example. I have no plans of stealing your code
and trying to re-sell it. I dont' charge for my shareware anyhow. (check
out random art or mines, but my creation and both freeware.)
If you have any code you would like to pass along, or know the exact location
of any (server, filename, path and all), please e-mail me back.
Thanks in advance for any help you can give me.
Ted.
+----------------------------+----------------------------+
| Ted Lowery | MacSolutions |
| tbl@rock.concert.net | PO Box 30051 |
| CIS: 76350,2613 | Raleigh, NC 27622 |
+----------------------------+----------------------------+
| Seen recently on a restroom wall next to the automatic |
| hand dryer... |
| "Push button for a message from your congressman." |
+---------------------------------------------------------+
+++++++++++++++++++++++++++
From: veloso@husc9.harvard.edu (Manuel Veloso)
Date: 25 Sep 92 15:46:55 GMT
Organization: Harvard University
In article <1992Sep24.171411.7499@nrtpa038.bnr.ca> Ted Lowery,
tbl@rock.concert.net writes:
>If you have any code you would like to pass along, or know the exact
location
>of any (server, filename, path and all), please e-mail me back.
Hi there,
what you've got to do is, when your init is run,
1) do any initializations which change actual code data,
2) create a new ptr in the system heap,
3) copy your init (shutdownproc, in this case) into the new pointer.
4) now install your shutdown proc (ShutDwnInstall)
why?
because your resource/init goes away after the INIT31 closes your
resource file (&demolishes the heap you're in). Luckily, I've just
finishing a shutdownproc init (how 'bout that), and the code (in
MPW assembler) is:
INITInstall PROC EXPORT
IMPORT myInit:CODE
IMPORT myInstall:CODE ; installs the shutdownproc
IMPORT getAlias:CODE
FirstResByte EQU myProc ; first 'real' procedure associated with
your init
start movem.l a0-a7/d0-d7, -(sp) ; save the registers!
move.l TheZone, a3 ; save the original zone
move.l SysZone, TheZone ; new systemzone.
lea start, a0 ; get loc of init
_RecoverHandle ; find the handle
_GetHandleSize ; how big? in D0
lea FirstResByte,A0 ; first byte of resident code
lea start,A1 ; first byte of header
sub.l A1,A0 ; size of header to be discarded
sub.l A0,D0 ; remove header from INIT to get resident size
move.l D0,D1 ; save size later for BlockMove
_NewPtr ,sys,clear ; make the resident block in System heap
tst.w d0 ; check for getting an error
bne.s exit ; got one, blow out
move.l A0,A1 ; save new location for _BlockMove
lea FirstResByte,A0 ; set A0 to source
move.l D1,D0 ; set D0 to size
_BlockMove
bsr myInstall ; installation routine
exit move.l a3, TheZone ; restore original zone
movem.l (sp)+, a0-a7/d0-d7 ; restore the registers
rts ; return to INIT 31
ENDP
END
NOTE: this routine should be linked in FIRST, and the 'real' code should
be linked in afterwords.
FirstResByte should be tqual to the first procedure following this
routine.
Basically, this code is apple's installation code for their jGNEFilter...
Manuel
+++++++++++++++++++++++++++
From: veloso@husc9.harvard.edu (Manuel Veloso)
Date: 26 Sep 92 16:13:25 GMT
Organization: Harvard University
In article <1992Sep25.114657.15843@husc3.harvard.edu> Manuel Veloso,
veloso@husc9.harvard.edu writes:
>Basically, this code is apple's installation code for their jGNEFilter...
Whoops! Sorry, but I forgot: the bsr myInstall has to be the myInstall in
the
new, allocated ptr so that, when you call shutdwninstall, the sdprocptr
points
to the proc in the ptr, not to some random hunk of memory where the init
resource
used to be.
Also, I haven't really tried this, but it seems that you could call a
detachresource
on yourself, so you wouldn't be purged out.
'luck,
Manuel
+++++++++++++++++++++++++++
From: peter@cujo.curtin.edu.au (Peter N Lewis)
Date: 29 Sep 92 03:12:26 GMT
Organization: NCRPDA, Curtin University
In article <1992Sep25.114657.15843@husc3.harvard.edu>, Manuel Veloso
<veloso@husc9.harvard.edu> wrote:
>
> In article <1992Sep24.171411.7499@nrtpa038.bnr.ca> Ted Lowery,
> tbl@rock.concert.net writes:
> >If you have any code you would like to pass along, or know the exact
> location
> >of any (server, filename, path and all), please e-mail me back.
> what you've got to do is, when your init is run,
> 1) do any initializations which change actual code data,
> 2) create a new ptr in the system heap,
> 3) copy your init (shutdownproc, in this case) into the new pointer.
> 4) now install your shutdown proc (ShutDwnInstall)
> because your resource/init goes away after the INIT31 closes your
> resource file (&demolishes the heap you're in).
An alternative that is often used is to mark your INIT resource as System
Heap and Locked, and then you just need to detach the resource before
INIT31 gets a chance to close your res file. So the only tricky bit is how
to get your address, which is conviniently placed in the ToolScratch
global.
Handle me;
me = RecoverHandle(ToolScratch);
DetachResource(me);
(you could add an HLock(me) in, but if the resource bits aren't set to
system heap its going to fail anyway when INIT31 trashes the current
"application" heap, so basically, make sure the resource bits are set
correctly!)
Have fun all,
Peter.
_______________________________________________________________________
Peter N Lewis, NCRPDA, Curtin University peter@cujo.curtin.edu.au
GPO Box U1987, Perth WA 6001, AUSTRALIA FAX: +61 9 367 8141
---------------------------
From: rpoldrac@s.psych.uiuc.edu (Russ Poldrack)
Subject: Random() needs some Thorazine (Help!)
Date: 24 Sep 92 22:35:24 GMT
Organization: UIUC Department of Psychology
I'm trying to get a simple set of random numbers in THINK C. I set
randSeed using GetDateTime(&randSeed), call Random(), and then assign
the value of randSeed to a long int variable, as suggested here
before. When I run this under the Debugger it seems to work fine,
giving a sequence of random numbers. However, when I run it without
the debugger or as an application it spits out the same number after
every call to RAndom(), i.e. the value of randSeed is not changed by
the call. Am I at fault here or should I just shoot my computer and
become a member of the clergy?
Russ
rpoldrac@psych.uiuc.edu
+++++++++++++++++++++++++++
From: rbarris@orion.oac.uci.edu (Robert C. Barris)
Date: 25 Sep 92 05:11:52 GMT
Organization: University of California, Irvine
In article <Bv3tF1.JvL@news.cso.uiuc.edu> rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
>I'm trying to get a simple set of random numbers in THINK C. I set
>randSeed using GetDateTime(&randSeed), call Random(), and then assign
>the value of randSeed to a long int variable, as suggested here
>before. When I run this under the Debugger it seems to work fine,
>giving a sequence of random numbers. However, when I run it without
>the debugger or as an application it spits out the same number after
>every call to RAndom(), i.e. the value of randSeed is not changed by
>the call. Am I at fault here or should I just shoot my computer and
>become a member of the clergy?
>
>Russ
>rpoldrac@psych.uiuc.edu
Did you call InitGraf? It's necessary.
+++++++++++++++++++++++++++
From: putnam@ux2.cso.uiuc.edu (Daniel E. Putnam - Invoice)
Date: 25 Sep 92 11:32:59 GMT
Organization: University of Illinois at Urbana
rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
>I'm trying to get a simple set of random numbers in THINK C. I set
>randSeed using GetDateTime(&randSeed), call Random(), and then assign
>the value of randSeed to a long int variable, as suggested here
>before. When I run this under the Debugger it seems to work fine,
>giving a sequence of random numbers. However, when I run it without
>the debugger or as an application it spits out the same number after
>every call to RAndom(), i.e. the value of randSeed is not changed by
>the call. Am I at fault here or should I just shoot my computer and
>become a member of the clergy?
>Russ
>rpoldrac@psych.uiuc.edu
I'll bet you are using the consoles that come with THINK C. The reason
for the failure is that THINK C calls InitGraf on its own private quickdraw
data structures.
You can try calling InitGraf on your own, but Inside MAC warns that you must
call InitGraf once and only once.
When I looked at this problem, it looked like THINK C was setting randSeed
as an offset from A5, but Random() was looking for randSeed at A0 - 0x7E.
Without calling InitGraf(), the two addresses didn't turn out to be the same.
Maybe you can write an asm that directly sets A0 - 7E. Its either that, or
do without THINK C consoles, or risk calling InitGraf twice, or use the srand()
and rand() that come with the THINK C libraries.
+++++++++++++++++++++++++++
From: manutter@grove.iup.edu (M. Nutter)
Date: 25 Sep 92 12:37:07 GMT
Organization: iup
In article <Bv4tF1.I8G@news.cso.uiuc.edu> Daniel E. Putnam - Invoice,
putnam@ux2.cso.uiuc.edu writes:
>rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
>
>>I'm trying to get a simple set of random numbers in THINK C. I set
>>randSeed using GetDateTime(&randSeed), call Random(), and then assign
>>the value of randSeed to a long int variable, as suggested here
>>before. When I run this under the Debugger it seems to work fine,
>>giving a sequence of random numbers. However, when I run it without
>>the debugger or as an application it spits out the same number after
>>every call to RAndom(), i.e. the value of randSeed is not changed by
>>the call. Am I at fault here or should I just shoot my computer and
>>become a member of the clergy?
>
>>Russ
>>rpoldrac@psych.uiuc.edu
>
>I'll bet you are using the consoles that come with THINK C. The reason
>for the failure is that THINK C calls InitGraf on its own private
quickdraw
>data structures.
>
>You can try calling InitGraf on your own, but Inside MAC warns that you
must
>call InitGraf once and only once.
>
>When I looked at this problem, it looked like THINK C was setting
randSeed
>as an offset from A5, but Random() was looking for randSeed at A0 - 0x7E.
>Without calling InitGraf(), the two addresses didn't turn out to be the
same.
>
>Maybe you can write an asm that directly sets A0 - 7E. Its either that,
or
>do without THINK C consoles, or risk calling InitGraf twice, or use the
srand()
>and rand() that come with the THINK C libraries.
No need to get so complicated: just make sure you set randSeed AFTER
you open your first window or console.
Also, I wouldn't worry about calling InitGraf twice. I routinely open
console windows after doing my own Toolbox initializations and haven't had
any problems.
+------------------------------------+
| Mark Nutter |
| manutter@grove.iup.edu |
+------------------------------------+
| Apple Support Manager |
| Indiana University of Pennsylvania |
| G-4 Stright, Indiana, PA 15705 |
+------------------------------------+
| Bonus question: Which of these |
| two statements is correct? |
| A) Statement "B" is false. |
| B) Statement "A" is true. |
+------------------------------------+
+++++++++++++++++++++++++++
From: fry@zariski.harvard.edu (David Fry)
Date: 25 Sep 92 17:24:48 EDT
Organization: Harvard Math Department
In article <2AC29F98.4352@news.service.uci.edu> rbarris@orion.oac.uci.edu (Robert C. Barris) writes:
>In article <Bv3tF1.JvL@news.cso.uiuc.edu> rpoldrac@s.psych.uiuc.edu (Russ Poldrack) writes:
>>I'm trying to get a simple set of random numbers in THINK C. I set
>>randSeed using GetDateTime(&randSeed), call Random(), and then assign
>>the value of randSeed to a long int variable, as suggested here
>>before. When I run this under the Debugger it seems to work fine,
>>giving a sequence of random numbers. However, when I run it without
>>the debugger or as an application it spits out the same number after
>>every call to RAndom(), i.e. the value of randSeed is not changed by
>>the call. Am I at fault here or should I just shoot my computer and
>>become a member of the clergy?
>>
>>Russ
>>rpoldrac@psych.uiuc.edu
>
>Did you call InitGraf? It's necessary.
If he hasn't called InitGraf and his program even runs, presumably
he's using the ANSI library. In this case don't call InitGraf because
it will confuse things, but call printf("\n") or some other routine
to trigger ANSI's own initialization procedure. Be sure to do this
before making any refernce to randSeed or calling Random().
David Fry fry@math.harvard.edu
Division of Applied Sciences fry@huma1.bitnet
Harvard University ...!harvard!huma1!fry
Cambridge, MA 02138
+++++++++++++++++++++++++++
From: putnam@ux2.cso.uiuc.edu (Daniel E. Putnam - Invoice)
Organization: University of Illinois at Urbana
Date: Sat, 26 Sep 1992 14:30:58 GMT
M. Nutter <manutter@grove.iup.edu> writes:
>No need to get so complicated: just make sure you set randSeed AFTER
>you open your first window or console.
Not so! The following program does not correctly generate new random numbers:
#include <console.h>
extern long randSeed;
main()
{
printf("Hello World\n");
GetDateTime(&randSeed);
printf("%d\n", Random());
}
Calling InitGraf(&thePort) after the first printf() seems to work despite
the warning in "Inside MAC". The first call to printf() already causes
the console library to initialize itself, including a call to InitGraf().
The following asm hack also works if you put it in after setting randSeed.
asm
{
MOVEA.L (A5), A0
MOVE.L randSeed, -0x7E(A0)
};
The "MOVEA.L (A5), A0" instruction is exactly what Random() does before
accessing A0 - 7E to get the value of randSeed. The two instructions
above just put the value of randSeed where Random() expects to find it.
None of this seems particularly satisfactory. If making the second call
to InitGraf() doesn't create havoc, I guess its OK.
+++++++++++++++++++++++++++
From: manutter@grove.iup.edu (M. Nutter)
Date: 29 Sep 92 11:54:10 GMT
Organization: iup
In article <Bv6wBn.5pF@news.cso.uiuc.edu> Daniel E. Putnam - Invoice,
putnam@ux2.cso.uiuc.edu writes:
>M. Nutter <manutter@grove.iup.edu> writes:
>
>>No need to get so complicated: just make sure you set randSeed AFTER
>>you open your first window or console.
>
>Not so! The following program does not correctly generate new random
>numbers:
>
> #include <console.h>
>
> extern long randSeed;
> main()
> {
> printf("Hello World\n");
> GetDateTime(&randSeed);
> printf("%d\n", Random());
> }
>
> [other stuff deleted]
Hmm, this is interesting. The above code does indeed generate the
same "random" number every time it is run. What is more interesting,
the following code also generates the same number every time, but the
number is different than the number generated by the above code:
#include <stdio.h>
main()
{
long dummy;
printf("\n");
GetDateTime(&dummy);
randSeed = dummy;
printf("%ld\n", Random());
}
The situation I was referring to (sorry for not making this clear
in my first post) is illustrated by the following code:
#include <stdio.h>
#include <useful.h> // my homebrew library of useful routines
// such as InitAll()
main()
{
long dummy;
InitAll(); // calls InitGraf, InitWindows, etc.
printf("%ld\n");
GetDateTime(&dummy);
randSeed = dummy;
printf("%ld\n", Random());
}
This code, compiled under Think C 5, generates a different
random number every time it is run.
+------------------------------------+
| Mark Nutter |
| manutter@grove.iup.edu |
+------------------------------------+
| Apple Support Manager |
| Indiana University of Pennsylvania |
| G-4 Stright, Indiana, PA 15705 |
+------------------------------------+
| Bonus question: Which of these |
| two statements is correct? |
| A) Statement "B" is false. |
| B) Statement "A" is true. |
+------------------------------------+
---------------------------
End of C.S.M.P. Digest
**********************